﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Silverlight.Testing;
using System8ToyMC;
using Numbers;
using System.Windows.Controls;
using ObjectDirectory;

namespace t_System8ToyMCControls
{
    [TestClass]
    public class t_EfficiencyUC : PresentationTest
    {
        private EfficiencyUC _val;
        private FlavorSample _num = new FlavorSample();
        private FlavorSample _denom = new FlavorSample();
        private epsilon_12 _eps;
        private TagEfficiency _tag = new TagEfficiency();

        [TestInitialize]
        public void SetupUI()
        {
            _val = new EfficiencyUC();
            _eps = new epsilon_12(_num, _denom);
            _val.EpsilonCL = _eps;
            _val.Efficiency = _tag;

            TestPanel.Children.Add(_val);
        }

        [TestMethod]
        public void TestCTor()
        {
        }

        [TestMethod]
        public void TestName()
        {
            _val.EfficiencyName = "eps 1234";
            TextBlock b = _val.FindName("TBName") as TextBlock;
            Assert.IsNotNull(b, "Can't get text block that matches the name");
            Assert.AreEqual("eps 1234", b.Text, "The name is not right!");
        }

        [TestMethod]
        public void TestSetTagEff()
        {
            NamedValue tbb = _val.FindName("TBEffB") as NamedValue;
            NamedValue tbc = _val.FindName("TBEffC") as NamedValue;
            NamedValue tbl = _val.FindName("TBEffL") as NamedValue;

            Assert.IsNotNull(tbb, "Missing B text box");
            Assert.IsNotNull(tbc, "Missing C text box");
            Assert.IsNotNull(tbl, "Missing L text box");

            Assert.AreNotEqual(0.33, tbb.Value, "Initial value is odd - b");
            Assert.AreNotEqual(0.34, tbc.Value, "Initial value is odd - c");
            Assert.AreNotEqual(0.35, tbl.Value, "Initial value is odd - l");

            _tag.eff_b = 0.33;
            _tag.eff_c = 0.34;
            _tag.eff_l = 0.35;

            Assert.AreEqual(0.33, tbb.Value, "value is odd - b");
            Assert.AreEqual(0.34, tbc.Value, "value is odd - c");
            Assert.AreEqual(0.35, tbl.Value, "value is odd - l");
        }

        [TestMethod]
        public void TestSetTagEffValues()
        {
            NamedValue tbb = _val.FindName("TBEffB") as NamedValue;
            NamedValue tbc = _val.FindName("TBEffC") as NamedValue;
            NamedValue tbl = _val.FindName("TBEffL") as NamedValue;

            Assert.IsNotNull(tbb, "Missing B text box");
            Assert.IsNotNull(tbc, "Missing C text box");
            Assert.IsNotNull(tbl, "Missing L text box");

            tbb.Value = 0.33;
            tbc.Value = 0.34;
            tbl.Value = 0.35;

            Assert.AreEqual(0.33, _tag.eff_b, "value is odd - b");
            Assert.AreEqual(0.34, _tag.eff_c, "value is odd - c");
            Assert.AreEqual(0.35, _tag.eff_l, "value is odd - l");
        }

        [TestMethod]
        public void TestEPS()
        {
            NamedValue eps = _val.FindName("TBEPSCL") as NamedValue;
            Assert.IsNotNull(eps, "Could not find the eps control");

            _num.Charm = 100;
            _denom.Charm = 200;

            Assert.AreEqual(0.5, eps.Value, "The eps's value isn't set correctly!");
        }

        public class TagHolder
        {
            public TagEfficiency eff { get; set; }
            public epsilon_12 eff_cl { get; set; }
        }

        [TestMethod]
        public void TestPath()
        {
            FlavorSample fs1 = new FlavorSample();
            FlavorSample fs2 = new FlavorSample();
            TagHolder th = new TagHolder() { eff = new TagEfficiency(), eff_cl = new epsilon_12(fs1, fs2) };

            _val.Path = "eff";
            Assert.AreEqual("eff", _val.Path, "path wasn't remembered correctly");

            NamedValue tbb = _val.FindName("TBEffB") as NamedValue;
            NamedValue tbc = _val.FindName("TBEffC") as NamedValue;
            NamedValue tbl = _val.FindName("TBEffL") as NamedValue;
            NamedValue tbcl = _val.FindName("TBEPSCL") as NamedValue;

            ObjectPathManager mgr = new ObjectPathManager();

            Assert.AreEqual(mgr.GetPath(th, th.eff.eff_bValue), tbb.Path, "eff_b isn't right");
            Assert.AreEqual(mgr.GetPath(th, th.eff.eff_cValue), tbc.Path, "eff_c isn't right");
            Assert.AreEqual(mgr.GetPath(th, th.eff.eff_lValue), tbl.Path, "eff_l isn't right");
            Assert.AreEqual(mgr.GetPath(th, th.eff_cl.ValueValue), tbcl.Path, "eff_cl isn't right!");
        }
    }
}